<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ page import="cap.bean.User" %>
<%@ page import="cap.bean.SysCategory" %>
<%@ page import="cap.bean.Article" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page isELIgnored="false"%>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<%
    User u = (User)request.getSession().getAttribute("user");//用户信息
    List<SysCategory> scList = (List<SysCategory>)request.getAttribute("scList");//博文分类信息
    List<User> uList = (List<User>)request.getAttribute("uList");//活跃博主信息
    List<Article> artList = (List<Article>)request.getAttribute("artList");//当前页码文章信息
    List<Article> tenList=(List<Article>)request.getAttribute("tenList");//博文top10
    int totalPages = (Integer)request.getAttribute("totalPages");//总页码
%>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="description" content="">
    <meta name="author" content="">
    <title>博客</title>
    <link href="<%=basePath%>bootstrap/css/blog-home.css"/>
    <link href="<%=basePath%>bootstrap/css/bootstrap.min.css" rel="stylesheet">
    <script src="<%=basePath%>bootstrap/js/jquery-2.1.1.js"></script>
</head>
<body>
<nav class="navbar navbar-inverse navbar-fixed-top" role="navigation"><!--导航条、反色、固定在顶部 -->
    <div class="container"><!--将导航条居中对齐并在两侧添加内补 -->
        <div class="navbar-header">
            <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
            </button>
            <a class="navbar-brand" href="#">博客</a><!--设置了内补（padding）和高度（height） -->
        </div>
        <!--导航链接，表格，和切换其他内容-->
        <div class="collapse navbar-collapse"><!--依赖collapse插件、视口足够窄.navbar-collapse内所包含的内容也将不可见-->
            <ul class="nav navbar-nav"><!--导航、导航项-->
                <li><a href="#">网站首页</a></li>
                <li><a href="<%=path%>/front/chatRoom.jsp">进入聊天室</a></li>
            </ul>
            <c:if test="${null!=user&&user.isApplied== 1}">
                <ul class="nav navbar-nav">
                    <li><a href="<%=basePath%>user?method=myblog&userId=${user.id}">我的博客</a></li>
                    <li><a href="<%=basePath%>article?method=manage&userId=${user.id}"><i class="glyphicon glyphicon-cog"></i> 博文管理</a></li><!--Glyphicons字体图标-->
                    <li class="divider"></li><!--分割线-->
                    <li><a href="<%=basePath%>category?method=manage&userId=${user.id}"><i class="glyphicon glyphicon-cog"></i> 分类管理</a></li><!--Glyphicons字体图标-->
                    <li class="divider"></li>
                    <li><a href="<%=basePath%>comment?method=manage&userId=${user.id}"><i class="glyphicon glyphicon-cog"></i> 评论管理</a></li>
                </ul>
            </c:if>
            <c:if test="${user==null}">
                <ul class="nav navbar-nav navbar-right">
                    <li><a href="<%=path%>/login.jsp" target="_self">登录</a></li>
                    <li><a href="<%=path%>/register.jsp" target="_self">注册</a></li>
                </ul>
            </c:if>
            <c:if test="${user!=null}">
                <div class="pull-right">
                    <ul class="nav navbar-nav navbar-right">
                        <li><a href="#">欢迎，${user.userName}</a></li>
                        <li><a href="<%=basePath%>user?method=profile&id=${user.id}"><i class="glyphicon glyphicon-cog"></i> 编辑个人信息</a></li>
                        <c:if test="${user.isApplied==1}">
                            <li><a href="<%=basePath%>user?method=bloginfo&userId=${user.id}"><i class="glyphicon glyphicon-cog"></i> 编辑博客信息</a></li>
                        </c:if>
                        <li><a href="<%=path%>/user?method=logout"><i class="glyphicon glyphicon-off"></i> 登出</a></li>
                    </ul>
                    </li>
                    </ul>
                </div>
            </c:if>
        </div>
    </div>
</nav>
<div style="position: relative;top: 80px">
    <div class="container"><!--栅格系统-->
        <div class="row"><!--预定义的类-->
            <div id="blog" class="col-md-8" ><!--中屏幕-->
                <c:if test="${user==null}">
                    <h1><a href="user?method=index">博客——<small>点击查看站内博客</small></a></h1><!--h1标题、small类-->
                </c:if>
                <c:if test="${user!=null}">
                    <h1><a href="user?method=index">博客——<small>开始写博客吧</small></a></h1><!--h1标题、small类-->
                </c:if>
                <br>
                <%if ((null != artList) && (artList.size() > 0)){
                    for (Article art : artList)
                    {//已经过滤删除的文章
                        //UserDaoImpl uDao = new UserDaoImpl();
                        //User user = uDao.getUserById(art.getUserId());
                        //ArticleCounter artCnt = artCntDao.getCounter(art.getId());
                        if (art != null) {
                %>
                <h3><a href="<%=basePath%>comment?method=post&artId=<%=art.getId()%>&userId=<%=art.getUserId()%>" target="_blank"><%=art.getTitle()%></a></h3><!--h3标题、博文标题 -->
                <p>
                    <i class="glyphicon glyphicon-user"></i> <!--user图标-->
                    <a href="<%=basePath%>user?method=myblog&userId=<%=art.getUserId()%>" target="_blank"><%=art.getUsername()%></a><!--作者名-->
                    <%
                        }
                    %>
                    | <i class="glyphicon glyphicon-calendar"></i> <%=art.getPublishTime()%><!--发表时间-->
                    | 阅读 <%=art.getCount()%> 次
                </p>
                <p><%=art.getSummary()%></p><br><!--博文摘要-->
                <a class="btn btn-primary" href="<%=basePath%>comment?method=post&artId=<%=art.getId()%>&userId=<%=art.getUserId()%>">阅读详细 <span class="glyphicon glyphicon-chevron-right"></span></a><!--图标按钮-->
                <hr>
                <%
                    }
                } else {
                %>
                <p>还没有写过文章哦，赶紧写吧~</p>
                <%
                    }
                %>
                <!-- 页码 -->
                <ul class="pager"><!--翻页-->
                    <c:if test="${curPage>1}">
                        <li class="previous"><a href="<%=basePath%>user?method=index&curPage=${curPage-1}">&larr; 上一页</a></li>
                    </c:if>

                    <c:if test="${curPage < totalPages}">

                        <li class="next"><a href="<%=basePath%>user?method=index&curPage=${curPage+1}">下一页  &rarr;</a></li>
                    </c:if>
                </ul>
            </div>

            <div class="col-md-4">
                <c:if test="${user!=null&&user.isApplied==0}">
                    <div class="well" align="center">
                        <a class="btn btn-primary" href="<%=basePath%>/front/ApplyBlog.jsp" target="_self">开通个人博客</a>
                    </div>
                </c:if>
                <c:if test="${user!=null&&user.isApplied==1}">
                    <div class="well" align="center"><!--警告框-->
                        <a class="btn btn-primary" href="<%=basePath%>user?method=myblog&userId=${user.id}">进入我的博客</a>
                    </div>
                </c:if>
                <div class="well">
                    <h4>搜索站内文章</h4>
                    <form name="search_form" action="<%=basePath%>user?method=search" method="post">
                        <div class="input-group"><!--输入框组-->
                            <input type="text" class="form-control" name="q"><!--输入框-->
                            <span class="input-group-btn"><!--任意一侧添加额外元素-->
                <button class="btn btn-default" type="submit"><span class="glyphicon glyphicon-search"></span></button><!--搜索按钮-->
              </span>
                        </div><!-- /input-group -->
                    </form>
                </div><!-- /well -->

                <form action="servlet/GetSysCategoryServlet" method="GET">
                    <div class="well">
                        <h4>网站分类</h4>
                        <div class="row">
                            <div class="col-md-6">
                                <ul class="list-unstyled"><!--无样式列表-->
                                    <%
                                        if ((null != scList) && (scList.size() > 0)) {
                                            for (SysCategory sc : scList) {
                                                if (sc.getIsDelete() == 0) {
                                    %>
                                    <li>
                                        <a href="<%=basePath%>index?method=indexFilter&sysCategoryId=<%=sc.getId()%>"><%=sc.getCategoryName()%></a>
                                    </li>
                                    <%
                                            }
                                        }
                                    } else {
                                    %>
                                    <li>无分类</li>
                                    <%
                                        }
                                    %>
                                </ul>
                            </div>
                        </div>
                    </div><!-- /well -->
                </form>

                <div class="well">
                    <h4>本周活跃博主</h4>
                    <div class="row">
                        <div class="">
                            <ul class="list-unstyled">
                                <%
                                    if ((null != uList) && (uList.size() > 0)) {
                                        int i = 1;
                                        for (User user : uList) {
                                %>
                                <li><a href="<%=basePath%>user?method=myblog&userId=<%=user.getId()%>" target="_blank"><%=i%>. <%=user.getUserName()%></a></li>
                                <%
                                        i++;
                                    }
                                } else {
                                %>
                                <li>暂无排名，抱歉......
                                </li>
                                <%
                                    }
                                %>
                            </ul>
                        </div>
                    </div>
                </div><!-- /well -->
                <div class="well">
                    <h4>博文TOP10</h4>
                    <div class="row">
                        <div class="">
                            <ul class="list-unstyled">
                                <%
                                    if(tenList!=null){
                                        int i=1;
                                        for(Article art:tenList){
                                %>
                                <li><a href="<%=basePath %>comment?method=post&artId=<%=art.getId() %>&userId=<%=art.getUserId() %>" target="_blank"><%=i %>. <%=art.getTitle() %></a></li>
                                <% 		i++;
                                }
                                } else {
                                %>
                                <li>暂无排名，抱歉......
                                </li>
                                <%
                                    }
                                %>
                            </ul>
                        </div>
                    </div>
                </div><!-- /well -->
            </div>
        </div>
    </div><!-- /.container -->
    <div class="container" style="position: absolute;left: 340px;bottom: -350px">
        <hr>
        <footer style="text-align: center">
            <div class="row">
                <div class="col-lg-12">
                    <p>
                        &middot;网站创建到目前访问人数：<%=(Integer)session.getAttribute("num") %>
                    </p>
                </div>
            </div>
        </footer>
    </div>
</div>
<div style="position: absolute;top: 70px"><audio autoplay="autoplay" controls="controls" loop="true"><source src="music/1.mp3"></audio></div>
</body>
<script>
    var d=document.getElementById("dropdown-menu1");
    d.onmouseenter=function(){
        d.setAttribute("aria-expanded","true");
    }
    d.onmouseout=function(){
        d.setAttribute("aria-expanded","false");
    }
</script>
</html>